package edu.tsinghua.ddb.main.gui.facade;

import edu.tsinghua.ddb.main.ExecuteSkeleton;
import edu.tsinghua.ddb.main.QuerySkeleton;
import edu.tsinghua.ddb.main.gui.QueryResult;

public class QueryGuiFactory {

	public static QueryGui getOne() {
		return new QueryGuiImpl();
	}
}

class QueryGuiImpl implements QueryGui {

	@Override
	public QueryResult execute(String sqlString) throws Exception {
		if (sqlString.toLowerCase().startsWith("select")) {
			QuerySkeleton qs = new QuerySkeleton(sqlString);
			return qs.getQueryResult();
		} else if (sqlString.toLowerCase().startsWith("insert")
				|| sqlString.toLowerCase().startsWith("delete")) {
			return new ExecuteSkeleton(sqlString).get();
		} else {

			throw new Exception("unsupport sql statment:" + sqlString);
		}
	}

}